package TwoPointer;

import java.util.Arrays;

/**
 * @Author: Darven
 * @CreateTime: 2025-03-30  19:31
 * @Description: TODO
 */
public class P238 {
    public static void main(String[] args) {
        P283Demo p283Demo = new P283Demo();
        int[] nums={0,1,0,3,12};
        p283Demo.moveZeroes(nums);
        System.out.println(Arrays.toString(nums));
    }
}

class P283Demo{
    public void moveZeroes(int[] nums) {
        int size=nums.length;

        for(int i=0;i<size;){
            if(nums[i]==0){
                for(int j=i;j<size-1;j++){
                    nums[j]=nums[j+1];
                }
                nums[size-1]=0;
                size--;
                continue;
            }
            i++;
        }

    }

    public void moveZeroes2(int[] nums) {
        int size=nums.length;
        int left=0;//
        int right=0;//left指向0 right指向非零，然后调换

        while (right<size){
            if(nums[right]!=0){
                int t=nums[left];
                nums[left]=nums[right];
                nums[right]=t;
                left++;
            }
            right++;
        }


    }
}
